package com.zzq.demo.tom.rest;

import com.gitee.sunchenbin.mybatis.actable.manager.handler.StartUpHandler;
import com.zzq.demo.tom.entity.TtModel;
import com.zzq.demo.tom.mapper.TtModelMapper;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;

/**
 * @author : zhaoziqian
 * @description :
 * @date : 2019/9/19 16:12
 */
@RestController
@RequestMapping("")
public class DemoController {

    @Resource
    private StartUpHandler startUpHandler;
    @Resource
    private TtModelMapper modelMapper;

    @GetMapping("")
    public String helloWorld() {
        return "hello world";
    }

    @GetMapping("/tt")
    public String test() {
        return "tttt234ttt234234t";
    }

    @GetMapping("/table")
    public String updateTable() {
        startUpHandler.startHandler();
        return "success";
    }

    @GetMapping("/map1/{price}")
    public String testMapper1(@PathVariable BigDecimal price) {
        List<TtModel> ttModels = modelMapper.selectByPrice(price);
        return ttModels.toString();
    }

    @GetMapping("/map2/{num}")
    public String testMapper2(@PathVariable Long num) {
        TtModel ttModel = modelMapper.selectByNum(num);
        if (ttModel == null) {
            return "NULL";
        }
        return ttModel.toString();
    }
}
